package com.quikin.web.controller.html.common;

import java.util.Locale;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.quikin.persistence.jpa.entity.aa.UserProfile;
import com.quikin.persistence.stdjpa.service.aa.AAEntryService;
import com.quikin.web.controller.html.HtmlController;
import com.quikin.web.controller.util.QuikinAPErrorCode;
import com.quikin.web.controller.util.QuikinAPException;

@Controller
public class CommonController extends HtmlController {
    
    @RequestMapping("html/login")
    public ModelAndView login(String email, String pass) {
        UserProfile user = AAEntryService.getInstance().login(email, pass);
        if (user == null) {
            throw new QuikinAPException(QuikinAPErrorCode.USER_NOT_EXIST);
        }
        ModelAndView mav = new ModelAndView();
        mav.setViewName("html/private/main");
        return mav;
    }

    @RequestMapping(value={"/","/html/index"}) 
    public ModelAndView b(HttpServletRequest req, Locale locale) throws Exception {
        ModelAndView mav = new ModelAndView();
        mav.setViewName("html/common/index");
        return mav;
    }
}
